using System;
using System.Collections.Generic;
using System.Linq;
using Granite.Xaml.Internals;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Granite.Xaml.Tests.Helpers;

namespace Granite.Xaml.Tests.ViewModel
{
	[TestClass]
	public class NavigationViewModelTests
	{
		[TestMethod]
		public void NavigationViewModel_NavigateTest1()
		{
			var navigator = new SimpleNavigator();
			var navigateAssert = new NavigateAssert(navigator);
			var openWebsiteAssert = new OpenWebsiteAssert(navigator);
			var result = new NavigationViewModel(navigator);

			result.Navigate("Home");
			navigateAssert.Expect("/Views/Home.xaml");

			result.NavigateCommand.Execute("About");
			navigateAssert.Expect("/Views/About.xaml");

			result.OpenWebsite("http://test.com");
			openWebsiteAssert.Expect("http://test.com/");

			result.OpenWebsite(new Uri("http://test2.com"));
			openWebsiteAssert.Expect("http://test2.com/");
		}

		[TestMethod]
		public void NavigationViewModel_NavigateTest2()
		{
			var navigator = new SimpleNavigator();
			var navigateAssert = new NavigateAssert(navigator);
			var result = new NavigationViewModel(navigator);

			result.NavigationFormatString = "";
			result.Navigate("Home");
			navigateAssert.Expect("Home");
		}

		[TestMethod]
		public void NavigationViewModel_NavigateTest3()
		{
			var navigator = new SimpleNavigator();
			var result = new NavigationViewModel(navigator);

			try
			{
				result.OpenWebsite((Uri)null);
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentNullException ex)
			{
				Assert.AreEqual("target", ex.ParamName);
			}
		}

		[TestMethod]
		public void NavigationViewModel_NavigateTest4()
		{
			var navigator = new SimpleNavigator();
			var result = new NavigationViewModel(navigator);

			try
			{
				result.OpenWebsite((String)null);
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentNullException ex)
			{
				Assert.AreEqual("target", ex.ParamName);
			}
		}

		[TestMethod]
		public void NavigationViewModel_NavigateTest5()
		{
			var navigator = new SimpleNavigator();
			var result = new NavigationViewModel(navigator);

			try
			{
				result.OpenWebsite("");
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentException ex)
			{
				Assert.AreEqual("target", ex.ParamName);
			}
		}
		[TestMethod]
		public void NavigationViewModel_ConstructorTest()
		{
			INavigator navigator = null;
			try
			{
				new NavigationViewModel(navigator);
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentNullException ex)
			{
				Assert.AreEqual("navigator", ex.ParamName);
			}
		}


	}
}
